/**
 * 
 */
package us.gaaoc.framework.webapp.backingbeans.profile;

import javax.faces.context.FacesContext;

import org.hibernate.HibernateException;

import us.gaaoc.framework.model.Person;
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;

/**
 * @author Sukhada
 * May 31, 2006
 * GAJE_BibbCounty_1.0
 */
public class ChangePassword extends BaseBackingBean {

	/**
	 * Default Serial Version UID
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * Properties
	 */	
	private String newPassword;
	private String confirmPassword;
	private String messageString;
	
	/**
	 * Constructor
	 *
	 */
	public ChangePassword() {
	}

	/**
	 * @return Returns the newPassword.
	 */
	public String getNewPassword() {
		return newPassword;
	}

	/**
	 * @param newPassword The newPassword to set.
	 */
	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	/**
	 * @return Returns the confirmPassword.
	 */
	public String getConfirmPassword() {
		return confirmPassword;
	}

	/**
	 * @param confirmPassword The confirmPassword to set.
	 */
	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	/**
	 * @return Returns the messageString.
	 */
	public String getMessageString() {
		return messageString;
	}

	/**
	 * @param messageString The messageString to set.
	 */
	public void setMessageString(String messageString) {
		this.messageString = messageString;
	}
	
	/**
	 * This method verifies the password entered by the user. If the password validates
	 * then this method changes the password of the user
	 * @return String
	 */
	public String changePassword(){
		FacesContext fc= this.getFacesContext();
		Person newPerson = (Person)fc.getExternalContext().getSessionMap().get("person");
		String oldpassword = newPerson.getPassword();
		newPerson.setPassword(getNewPassword());
		getModelFacade().getSession().update(newPerson);
		return "viewProfile";
	}
}
